<?php

class Admin_Model extends CI_Model{
    function __construct(){
        parent::__construct();
    }
	
	function admin_login(){
		$query = $this->db->query('SELECT login_id, MD5(CONCAT(login_password)) FROM user WHERE login_id=' . "'" . $this->input->post('username') . "'" . ' AND login_password=' . "'" . md5($this->input->post('password')) ."' AND user_role_id=1");
		if($query->num_rows()==1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
	
	//category methods
	function get_category_lists(){
		$query = "SELECT * FROM categories";
		return $this->db->query($query);
	}
	
	function get_category_by_id($id){
		$query = "SELECT * FROM categories WHERE category_id=$id";
		return $this->db->query($query);
	}
	
	function update_category_by_id(){
		$query = $this->db->query('UPDATE categories SET meta_keywords="' . mysql_real_escape_string($_POST['meta_keywords']) . '" WHERE category_id=' . $_POST['category_id']);
		if($query){
			return TRUE;
		}else{
			return FALSE;
		}
	}
	
	//product methods
	function get_product_lists(){
		$query = "SELECT * FROM products";
		return $this->db->query($query);
	}
	
	function get_product_by_id($id){
		$query = "SELECT * FROM products WHERE product_id=$id";
		return $this->db->query($query);
	}
	
	function update_product_by_id(){
		$query = $this->db->query('UPDATE products SET meta_keywords="' . mysql_real_escape_string($_POST['meta_keywords']) . '" WHERE product_id=' . $_POST['product_id']);
		if($query){
			return TRUE;
		}else{
			return FALSE;
		}
	}
}